package com.holly.unit.bpmn.designer.core.strategy;

import com.holly.unit.bpmn.designer.constants.BpmnDesignerConstants;
import com.holly.unit.bpmn.designer.core.bpmn.BpmnModelFactory;
import com.holly.unit.bpmn.designer.enums.ApprovalModeEnum;
import com.holly.unit.bpmn.designer.model.ChildNode;
import com.holly.unit.bpmn.designer.model.TreeSelectModel;
import org.activiti.bpmn.model.UserTask;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 类描述: 指定人员 策略
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/5/13 9:07
 */
public class CreateCandidateUsersTaskStrategy implements CreateTaskStrategy{

    @Override
    public UserTask createTask(ChildNode node,BpmnModelFactory factory) {

        UserTask userTask =null;
        List<TreeSelectModel> users = node.getProperties().getApprovers();
        List<String> userIds = users.stream().map(TreeSelectModel::getId).collect(Collectors.toList());

        // 会签任务
        if (node.getProperties().getOptionalMultiUser().equals(ApprovalModeEnum.COUNTER_SIGN.fieldName())) {

            userTask = factory.createCountersignCandidateUsersTask(node.getNodeId(),node.getProperties().getTitle(),
                    BpmnDesignerConstants.COUNTER_SIGN_ASSIGN_LIST,
                    BpmnDesignerConstants.COUNTER_SIGN_ASSIGNEE_NAME,
                    BpmnDesignerConstants.COUNTER_SIGN_COMPLTE_CONDITION,
                    BpmnDesignerConstants.COUNTER_SIGN_ASSIGNNAME,userIds);
        } else if (node.getProperties().getOptionalMultiUser().equals(ApprovalModeEnum.OR_SIGN.fieldName())) {//或签任务
            userTask = factory.createCandidateUsersTask(node.getNodeId(),node.getProperties().getTitle(),userIds);
        } else if (node.getProperties().getOptionalMultiUser().equals(ApprovalModeEnum.NEXT_SIGN.fieldName())) {//顺序签
            // TODO 顺序签
        }

        return userTask;
    }
}
